<template>
  <div class="" style="height: 100%">
    <beijingdatatable :header="header" :datalist="datalist" />
  </div>
</template>
<script>
import commonmixins from "@/mixins/bigScreen/commonmixins";
import axios from "@/utils/requestdp";

export default {
  name: "warntable",
  mixins: [commonmixins],
  components: {},
  data() {
    return {
      header: [],
      datalist: [],
    };
  },
  computed: {},
  watch: {},
  mounted() {
    let unitcolor = "#56C5FA";
    this.header = [
      {
        name: `告警等级`,
        flex: 2,
      },
      {
        name: `告警时间`,
        flex: 2,
      },
      {
        name: `告警来源`,
        flex: 2,
      },
      {
        name: `异常数值`,
        flex: 2,
      },
      {
        name: `告警内容`,
        flex: 2,
      },
    ];
    this.header = this.header.map((item) => {
      item.name = "<div>" + item.name + "</div>";
      return item;
    });
    this.loadData();
  },
  methods: {
    getLevelStyle(level) {
      let color = "";
      switch (level) {
        case "一级":
          color = "#E4847A";
          break;
        case "二级":
          color = "#EDAF33";
          break;
        case "三级":
          color = "#E4E26A";
          break;
      }
      return color;
    },
    loadData() {
      axios.post('warn/msg/list', {}).then(res => {
        if (res.rows.length > 0) {
          let rs = res.rows;
          let aaa = [];
          rs.forEach(r => {
            aaa.push({
              level: `<span class="warn-name" style="border: ${'1px solid ' + r.levelColor};color: ${r.levelColor}">${r.levelName}</span>`,
              riseTime: r.riseTime,
              name: r.name,
              warnValue: r.warnValue,
              content: r.remark + ((r.warnValue > r.value) ? '过高' : '过低')
            })
          })
          this.datalist = aaa;
          this.$nextTick(() => {
            let name = document.querySelectorAll('.warn-name');
            name.forEach(v => {
              v.style.width = this.getscalepx(60);
              v.style.height = this.getscalepx(20);
              v.style.lineHeight = this.getscalepx(20);
            })
          })
        } else {
          this.datalist = [];
        }
      })
    }
  },
};
</script>
<style lang='scss'
>
.warn-name {
  display: inline-block;
}
</style>